
<Serializable()> Friend Class Variables
    Private m_description As String = vbNullString
    Private m_firstNode As Variable

    Friend Sub New(ByVal Description_ As String)
        m_description = Description_
    End Sub

    Friend Sub addNode(ByRef Var_ As Variable)
        If Not IsNothing(Var_) Then
            If IsNothing(m_firstNode) Then
                m_firstNode = Var_
            Else
                If m_firstNode.getName <> Var_.getName Then
                    m_firstNode.addNode(Var_)
                End If
            End If
        End If
    End Sub
    Friend Sub addNode(ByVal Name_ As String, ByVal Description_ As String)
        If IsNothing(m_firstNode) Then
            m_firstNode = New Variable(Name_, Description_)
        Else
            m_firstNode.addNode(New Variable(Name_, Description_))
        End If
    End Sub
    Friend Sub addNode(ByVal Name_ As String, ByVal Description_ As String, ByVal Address_ As Integer)
        If IsNothing(m_firstNode) Then
            m_firstNode = New Variable(Name_, Description_, Address_)
        Else
            m_firstNode.addNode(New Variable(Name_, Description_, Address_))
        End If
    End Sub
    Friend Sub addNode(ByVal Name_ As String, ByVal Description_ As String, ByVal Address_ As Integer, ByVal Multiplier_ As Double, ByVal Length_ As Byte)
        If IsNothing(m_firstNode) Then
            m_firstNode = New Variable(Name_, Description_, Address_, Multiplier_, Length_)
        Else
            m_firstNode.addNode(New Variable(Name_, Description_, Address_, Multiplier_, Length_))
        End If
    End Sub

    Friend Function getDescription() As String
        Return m_description
    End Function
    Friend Function getFirst() As Variable
        If IsNothing(m_firstNode) Then
            Return Nothing
        Else
            Return m_firstNode
        End If
    End Function

    Friend Sub setDescription(ByVal Description_ As String)
        m_description = Description_
    End Sub

    Friend Function length() As Integer
        Dim retInt As Integer = 0
        If Not IsNothing(m_firstNode) Then
            retInt = m_firstNode.lengthTotal
        End If
        Return retInt
    End Function
    Friend Function count() As Integer
        Dim intReturn As Integer = 0
        If Not IsNothing(m_firstNode) Then
            intReturn = m_firstNode.count
        End If
        Return intReturn
    End Function
    Friend Function getByName(ByVal Name_ As String) As Variable
        Dim f_cursor As Variable
        Dim found As Boolean = False
        Name_ = LCase(Name_)
        If Not IsNothing(m_firstNode) Then
            f_cursor = m_firstNode
            If LCase(f_cursor.getName) = Name_ Then
                found = True
                GoTo endMod
            End If
            While Not found
                If Not IsNothing(f_cursor.getnext) Then
                    f_cursor = f_cursor.getnext
                    If LCase(f_cursor.getName) = Name_ Then
                        found = True
                        GoTo endMod
                    End If
                Else
                    found = False
                    GoTo endMod
                End If
            End While
        Else
            Return Nothing
        End If
endMod:
        If found Then Return f_cursor Else Return Nothing
    End Function
    Friend Function getByAddress(ByVal Address_ As Integer) As Variable
        Dim f_cursor As Variable
        Dim found As Boolean = False
        If Not IsNothing(m_firstNode) Then
            f_cursor = m_firstNode
            If f_cursor.getAddress = Address_ Then
                found = True
                GoTo endMod
            End If
            While Not found
                If Not IsNothing(f_cursor.getnext) Then
                    f_cursor = f_cursor.getnext
                    If f_cursor.getAddress = Address_ Then
                        found = True
                        GoTo endMod
                    End If
                Else
                    found = False
                    GoTo endMod
                End If
            End While
        Else
            Return Nothing
        End If
endMod:
        If found Then Return f_cursor Else Return Nothing
    End Function
    Friend Function getByIndex(ByVal Index_ As Integer) As Variable
        Dim f_cursor As Variable
        Dim found As Boolean = False
        If Not IsNothing(m_firstNode) Then
            f_cursor = m_firstNode
            If Index_ = 0 Then
                Return f_cursor
                found = True
            Else
                For count As Integer = 1 To Index_
                    If Not IsNothing(f_cursor.getnext) Then
                        f_cursor = f_cursor.getnext
                        found = True
                    Else
                        Return Nothing
                        Exit For
                    End If
                Next
            End If
        Else
            Return Nothing
        End If
        If found = False Then Return Nothing Else Return f_cursor
    End Function
    Friend Function getAsArray() As Variable()
        Dim f_count As Integer
        Dim f_varArray() As Variable = Nothing
        If Not IsNothing(m_firstNode) Then
            f_count = m_firstNode.count
            ReDim f_varArray(0 To f_count - 1)
            For i As Integer = 0 To f_count - 1
                f_varArray(i) = Me.getByIndex(i)
            Next
        End If
        Return f_varArray
    End Function
    Friend Function removeByAddress(ByVal Address_ As Integer) As Boolean
        Dim s_first As Variable
        Dim s_temp As Variable
        Dim found As Boolean = False

        If Not IsNothing(m_firstNode) Then
            If m_firstNode.getAddress = Address_ Then
                If IsNothing(m_firstNode.getnext) Then
                    m_firstNode = Nothing
                Else
                    s_temp = m_firstNode.getnext
                    m_firstNode = Nothing
                    Me.addNode(s_temp)
                End If
            Else
                ' First node not a match.. now check all other nodes
                s_first = m_firstNode
                Do
                    If s_first.getnext.getAddress = Address_ Then
                        'next node is a match..
                        If IsNothing(s_first.getnext.getnext) Then
                            'next node has no next.. so just null delete the link
                            s_first.setNext(Nothing)
                            found = True
                            GoTo endSub
                        Else
                            'the next node has a next.. so must swap the links
                            s_temp = s_first.getnext.getnext
                            s_first.setNext(s_temp)
                            found = True
                            GoTo endSub
                        End If
                    End If
                    s_first = s_first.getnext
                Loop Until found Or IsNothing(s_first.getnext)
            End If
        End If
endSub:
        s_first = Nothing
        s_temp = Nothing
        If found Then Return True Else Return False
    End Function
    Friend Function removeByIndex(ByVal Index_ As Integer) As Boolean
        Dim ret As Boolean = False
        Dim f_name As String
        Dim f_map As Variable
        f_map = Me.getByAddress(Index_)
        If Not IsNothing(f_map) Then
            f_name = f_map.getName()
            ret = Me.removeByName(f_name)
        End If
        Return ret
    End Function
    Friend Function removeByName(ByVal Name_ As String) As Boolean
        Dim s_first As Variable
        Dim s_temp As Variable
        Dim found As Boolean = False

        If Not IsNothing(m_firstNode) Then
            If LCase(m_firstNode.getName) = (Name_) Then
                If IsNothing(m_firstNode.getnext) Then
                    m_firstNode = Nothing
                Else
                    s_temp = m_firstNode.getnext
                    m_firstNode = Nothing
                    Me.addNode(s_temp)
                End If
            Else
                ' First node not a match.. now check all other nodes
                s_first = m_firstNode
                Do
                    If LCase(s_first.getnext.getName) = (Name_) Then
                        'next node is a match..
                        If IsNothing(s_first.getnext.getnext) Then
                            'next node has no next.. so just null delete the link
                            s_first.setNext(Nothing)
                            found = True
                            GoTo endSub
                        Else
                            'the next node has a next.. so must swap the links
                            s_temp = s_first.getnext.getnext
                            s_first.setNext(s_temp)
                            found = True
                            GoTo endSub
                        End If
                    End If
                    s_first = s_first.getnext
                Loop Until found Or IsNothing(s_first.getnext)
            End If
        End If
endSub:
        s_first = Nothing
        s_temp = Nothing
        If found Then Return True Else Return False
    End Function
End Class